package org.bt.forecast.utils;

import java.util.ArrayList;
import java.util.List;

public class Constant {
    //双色球
    public static final String ssqApi = "https://datachart.500.com/ssq/history/newinc/history.php?start=3000&end=";
    //大乐透
    public static final String dltApi = "https://datachart.500.com/dlt/history/newinc/history.php?start=07000&end=";

    private final static int[] ssq_red = new int[]{
            0, 1, /*2,*/
            3, 4, 5, /*6,*/
            7, 8, 9, 10, /*11, 12,*/
            13, 14, 15, 16, 17, /*18, 19,*/
            20, 21, 22, 23, /*24, 25,*/
            26, 27, 28, /*29,*/
            30, 31, /*32*/
    };
    private final static int[] ssq_blue = new int[]{
            0,
            1, /*2,*/
            3, 4, /*5,*/
            6, 7, 8, /*9,*/
            10, 11, /*12,*/
            13, /*14,*/
            15
    };
    private final static int[] dlt_red = new int[]{
            0, 1, /*2,*/
            3, 4, 5, 6, /*7,*/
            8, 9, 10, 11, /*12, 13,*/
            14, 15, 16, 17, /*18, 19, 20,*/
            21, 22, 23, 24, /*25, 26,*/
            27, 28, 29, 30, /*31,*/
            32, 33, /*34*/
    };
    private final static int[] dlt_blue = new int[]{
            0,
            1,
            2, /*3,*/
            4, 5, 6,/* 7,*/
            8, /*9,*/
            10,
            11
    };

    //根据规则挑选集合
    public static List<String> getList(String type, String color, List<String> list) {
        List<String> newList = new ArrayList<>();
        if (type.equals("ssq")) {
            if (color.equals("red")) {
                for (int i : ssq_red) {
                    newList.add(list.get(i));
                }
            } else {
                for (int i : ssq_blue) {
                    newList.add(list.get(i));
                }
            }
        } else {
            if (color.equals("red")) {
                for (int i : dlt_red) {
                    newList.add(list.get(i));
                }
            } else {
                for (int i : dlt_blue) {
                    newList.add(list.get(i));
                }
            }
        }
        return newList;
    }

    //Object转List
    public static <T> List<T> castList(Object obj, Class<T> clazz) {
        List<T> result = new ArrayList<T>();
        if (obj instanceof List<?>) {
            for (Object o : (List<?>) obj) {
                result.add(clazz.cast(o));
            }
            return result;
        }
        return null;
    }
}
